﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZBJF.Warranty.BLL;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Common.Enums.InsuranceWarranty;
using ZBJF.Warranty.Model.ViewModel.InsuranceWarranty;

namespace ZBJF.Warranty.CustomerService.Controllers
{
    public class ProcessedWorkOrderController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        #region 获取已处理报案工单任务列表数据 + JsonResult Index(InsuranceWarrantyRecordModel model)
        /// <summary>
        /// 获取报案工单任务列表数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Index(InsuranceWarrantyRecordModel model)
        {
            var total = 0;
            var list = ServiceFactory.InsuranceWarrantyRecordServiceInstance.GetPagingList(model, out total).Include(o => o.SystemUser).Include(o => o.InsuranceOrder).AsNoTracking().ToList().Select(o => new
            {
                o.ID,
                o.WarrantyRecordNo,//报案号
                o.Reporter,//报案人姓名
                o.ReporterPhone,       //报案人电话     
                StatusDesc = ServiceFactory.InsuranceWarrantyRecordStatusServiceInstance.GetStatusName(o.Status),//工单状态
                CreateTime= o.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),//创建时间
                LastModifyTime=o.LastModifyTime.ToLongDateString(),//最后编辑时间
                ServiceUserName = o.SystemUser != null ? o.SystemUser.UserDisPlayName : string.Empty,//当前跟进人
                o.InsuranceOrder.InsuranceCompany,//承保公司
                o.InsuranceOrder.InsuranceCompanyBranch,//承保分公司
                o.InsuranceOrder.ProductName,//保险产品名称
                o.InsuranceOrder.ProductTypeName,//保险产品类型
                o.InsuranceOrder.SaleVendorName,//销售商户
                o.InsuranceOrder.InsuranceCategoryName,
                CostTotalSecond = CommonMethod.TimeSencondToString(o.CostTotalSecond ?? (int)(DateTime.Now - o.CreateTime).TotalSeconds),//总耗时
            }).ToList();
            return Json(new
            {
                sEcho = model.sEcho,
                iTotalRecords = total,
                iTotalDisplayRecords = total,
                aaData = list
            }, JsonRequestBehavior.AllowGet);
        }
        #endregion
        public ActionResult Detail(int id)
        {
            var insuranceWarrantyRecord = ServiceFactory.InsuranceWarrantyRecordServiceInstance.LoadByID(id);
            return View(insuranceWarrantyRecord);
        }
    }
}